package com.huabo.monitor.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huabo.monitor.entity.TblTestplan;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huabo.monitor.entity.TblTestplanVo;
import com.huabo.monitor.entity.TblTesttempleVo;
import com.huabo.monitor.entity.Tree;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author yhr
 * @since 2022-09-07
 */
@Mapper
public interface TblTestplanMapper extends BaseMapper<TblTestplan> {



    @Select("${sql}")
    <p extends IPage<TblTestplan>>  p  getSqlPage(p page, @Param("sql") String sql);

    @Select("select * from TBL_TESTPLAN where testplanid=#{testplanid}")
    @Results(id="TblTestplanVo",value={
            @Result(property = "testplanid",column = "testplanid",id = true),
            @Result(property = "testtemid",column = "testtemid"),
            @Result(property = "orgid",column = "orgid"),
            @Result(property = "creatid",column = "creatid"),
            @Result(property = "staffid",column = "staffid"),
            @Result(property = "testtemple",column = "testtemid",one=@One(select="com.huabo.monitor.mapper.TblTesttempleMapper.selectById")),

    })
    TblTestplanVo getOneTblTestplanVo(BigDecimal testplanid);

    @Select("select * from TBL_TESTTEMPLE where testtemid=#{testtemid}")
    @Results(id="TblTesttempleVo",value={
            @Result(property = "staffid",column = "staffid"),
            @Result(property = "chuangjianren",column = "staffid",one=@One(select="com.huabo.monitor.mapper.TblStaffMapper.selectById")),

    })
    TblTesttempleVo getOneTblTesttempleVo(@Param("testtemid") BigDecimal testtemid);



    @Select("${sql}")
    @ResultMap("TblTesttempleVo")
    <p extends IPage<TblTesttempleVo>>  p  getTesttempleVoSqlPage(p page, @Param("sql") String sql);



    @Select("select\n" +
            "    decode(CONNECT_BY_ISLEAF,0,'true','false') AS \"isParent\",\n" +
            "    t.typeid as \"id\",\n" +
            "    t.TYPENAME as \"name\",\n" +
            "    t.PARENTID as \"pId\"\n" +
            "from TBL_TESTTEMPL_TYPE t\n" +
            "CONNECT BY PRIOR T.TYPEID = T.PARENTID\n" +
            "START WITH t.parentId is null and t.testTempletaId = #{tempid}")
    List<Tree> getTreeListByTemid(BigDecimal tempid);


    /*
        分配右侧列表
     */
    @Select("${sql}")
    IPage<Map<String,Object>>  fingByTree(IPage<Map<String,Object>> page, @Param("sql") String sql);


}
